<?php

namespace lvzmen\yii\cms\widgets\navs;

use Yii;
use yii\base\Widget;
use yii\bootstrap\NavBar;

/**
 * A menu imitate the sidebar of https://docs.docker.com/get-started/
 *
 * @note It's depend on bootstrap;
 *
 * @example :
 * ```php
 * echo \lvzmen\yii\cms\widgets\navs\Nav::widget([
 *     "brandImage" => "/images/logo.png",
 *     "rightNavs" => [
 *         ['label' => 'Home', 'url' => ['/yii2/home']],
 *         ['label' => 'Bootstrap3', 'url' => ['/yii2/bootstrap3']],
 *     ]
 * ])
 * ```
 * @author chenzhiwei <chenzhiweiwk@qq.com>
 * @date   2021/08/31
 */
class Nav extends Widget
{

    //brand setting
    public $brandImage;
    public $brandLabel;
    public $brandUrl;

    //.nav-fixed-top true/false
    public $isFixed = true;

    //the nav list for right / left nav
    public $rightNavs;
    public $leftNavs;

    public $class = "nav nav-bar";
    public $style = "";

    public function init()
    {
        parent::init(); // TODO: Change the autogenerated stub
        if ($this->isFixed) {
            $this->class = "nav nav-bar navbar-fixed-top cms-nav";
        }
        $this->addCss();
    }

    public function run()
    {
        parent::run(); // TODO: Change the autogenerated stub

        return NavBar::widget([
            "brandImage"  => $this->brandImage,
            "brandLabel" => $this->brandLabel,
            "brandUrl" => $this->brandUrl,
            'options' => [
                'class' => $this->class,
                'style' => $this->style,
            ],
            "headerContent" => \yii\bootstrap\Nav::widget([
                'options' => ['class' => 'navbar-nav navbar-left'],
                'items' => $this->rightNavs ?: [],
            ])
        ]);
    }


    public function addCss(){
        $css = <<<CSS
.cms-nav {
    background-color: #2697ed; 
    border-radius: 0;
}
.cms-nav li a {
    color: #fafafa;!important;
    font-weight: 600;
}
.cms-nav li a:hover {
    background-color: #2697ed!important;
    border-bottom: 4px solid rgba(255,255,255,0.5);
    border-left: none;
}
.cms-nav li.active a {
    background-color: #2697ed!important;
    border-bottom: 4px solid rgba(255,255,255,0.5);
    border-left: none;
}
.cms-nav .navbar-brand img {
    height: 40px;
    margin-top:-10px;
    max-width: 100%;
    vertical-align: middle;
    border-style: none;
}
CSS;
        $this->view->registerCss($css);
    }
}
